<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>课程库</title>
<script type="text/javascript" src="static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="static/easyui/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" href="static/easyui/themes/icon.css">
<link rel="stylesheet" href="static/easyui/themes/metro-blue/easyui.css">
</head>
<body>
<style type="text/css">
.background{
	width:1115px;
	height:565px;
	margin: 0px auto;
	margin-top: 17px;
	background-color: #FFF;
}
.textbox{
	z-index:1;
}
#qx_tree{
	z-index:2;
}
#textpxmc{
	margin-left:26px;
}
</style>
<script type="text/javascript">

	$(function(){
		$("#qx_tree").hide();
		
		$("#xinadd").click(function(){
			 $("#content-admin").panel('open').panel('refresh','train-add');
		});
		
		
		$("#staff_id").dblclick(function(){
			$("#qx_tree").hide();
		});
			$("#staff_id").click(function(){
				$("#qx_tree").show();
			});
			
		//部门，，员工树状图
			$('#qx_tree').tree({
				checkbox:true,
				onlyLeafCheck:true,
			    url:'select-ppp',
			    onCheck:function(node){
			    	var nodes = $('#qx_tree').tree('getChecked');
					var names=[];
					var ids=[];
					//循环选中的节点
					for (var i = 0; i < nodes.length; i++) {
						//获取三级功能id，存入数组
						names.push(nodes[i].text);
						ids.push(nodes[i].id);
						/* //根据三级的节点，获取二级
						var parent = $("#qx_tree").tree("getParent",nodes[i].target);
						if(parent != null){
							names.push(parent.text);
							ids.push(parent.id);
							
							//根据二级的节点，获取一级
							 var root = $("#qx_tree").tree("getParent",parent.target);
							if(root != null){
								names.push(root.text);
							} 
						} */
					}
					
					//去重
					function dedupe(array){
						 return Array.from(new Set(array));
					}
					
					names = dedupe(names) //保证一级和二级在数组中不重复
					ids=dedupe(ids)
					$("#staff_id").val(names);
					$("#idss").val(ids);
			    }
		});  
	})
	
		
</script>
<div class="background">
	<div style="width:calc(100% - 200px);margin:auto;">
	<div style="width:calc(100% - 40px);height:48px;border-bottom:1px solid #ccc;">
		<a id="xinadd" style="float:right;padding:3px 15px;margin: 10px 2px 10px 0;font-size: 14px;background: #19AA8D;color: white;border-radius: 3px;">新建课程</a>
	</div>
	
	<div style="width:calc(100% - 40px);">
	<c:forEach items="${courseku }" var="i">
		<input type="hidden" value="${i.course_hour}" id="course_hour"/>
		<input type="hidden" value="${i.pxapproval_state }" id="static"/>
		<div style="width:100%;height:120px;margin:20px auto;border-bottom: 1px solid rgb(204, 204, 204);">
			<div style="width: 115px;height:80px;border:3px solid rgb(204, 204, 204);float:left;margin:20px 0;">
				<img alt="" src="${i.course_url}" style="width:115px;height:80px"/>
			</div>
			<div style="width:350px;height:80px;float:left;margin:20px 0 20px 10px;">
				<p style="margin: 15px 0;font-size:14px;font-weight:700px;color:#19AA8D;">${i.course_name}</p>
				
				<p style="margin:15px 0;font-size:12px;color:#666;">
					<span>培训讲师：</span><span>${i.Staff_name}</span>
					<span style="margin-left:20px;">课程详情：</span><span>${i.course_details}</span>
					<span style="margin-left:20px;">课程类型：</span><span>${i.course_type}</span>
				</p>
			</div>
			<div style="width:139px;height:55px;margin-top:30px;float:right;margin:20px 0;">
				<input type="hidden" value="${i.course_id}" id="course_id"/>
				<c:if test="${i.pxapproval_state==3}">
					<a id="jinyong-button" style="width:79px;height:25px;margin-top:30px;text-align:center;line-height:25px;font-size: 12px;border-radius: 3px;color: #fff!important;
				background-color: #19AA8D;border-color: #19AA8D;display: inline-block;" onClick="peixun(${i.course_id})">发起培训</a>
				</c:if>
				<c:if test="${i.pxapproval_state==1}">
				<a id="jybuttons1"style="width:79px;text-align:center;line-height:25px;height:25px;font-size: 12px;border-radius: 3px;color: #fff;
				    background-color: #19AA8D;border-color: #19AA8D;display: inline-block;" onClick="shenqing(${i.apply_id},${i.pxapproval_id},${i.course_id})">发起申请</a>
				</c:if>
				<c:if test="${i.pxapproval_state==2}">
				<a id="shanchu"style="width:79px;text-align:center;line-height:25px;height:25px;font-size: 12px;border-radius: 3px;color: #fff;
				    background-color: #d9534f;border-color: #19AA8D;display: inline-block;">已停用</a>
				</c:if>
			</div>	
		</div>	
		</c:forEach>	
	</div>
	</div>
</div>	
	<div id="zhezhaoceng" style="width:1366px;height:736px;position:fixed; top:0px;background:rgba(0, 0, 0, 0.5);text-align:center;left:0;z-index:10;display:none;" >
		<div style="margin:20px auto;width:500px;height:280px;background:white;border-radius:3px;">
	<div style="width:100%;height:30px;">
		<span style="width:50px;height:30px;line-height:30px;display:inline-block;float:left;margin-left:20px;" class="xinzeng_text">发起培训</span>
		<button class="icon-close guanbiya" style="float:right;width:30px;height:30px;cursor:pointer;border:none;outline:none;"></button>
	</div>
	<div style="width:100%;height:210px;border-top:solid 1px #E5E5E5;border-bottom:solid 1px #E5E5E5;">
		<input type="hidden" id="cours_id"/>
		<p>
			<span id="textpxmc">培训名称：</span><input type="text" id="act-name" style="border:1px solid #A9A9A9;"/>
		</p>
		<p>
			<span>培训部门/人员：</span><input type="text" id="staff_id" readonly="readonly"/>
			<ul id="qx_tree" style="margin:7px auto;padding-top:20px;width:194px;height:240px;border:solid 1px;position: absolute;
    		left: 640px;top: 110px;background:white;"></ul>
		</p>
		<p>
			<span id="textpxmc">开始时间：</span><input type="text" id="act-start" class="easyui-datetimebox" required="required" editable="false" style="width:173px;border:1px solid #A9A9A9;"/>
		</p>
		<p>
			<span id="textpxmc">结束时间：</span><input type="text" id="act-end" class="easyui-datetimebox" required="required" editable="false" style="width:173px;border:1px solid #A9A9A9;"/>
		</p>
		<p>
			<span id="textpxmc">培训地点：</span><input type="text" id="act-address"/>
		</p>
		<p>
			<span id="textpxmc" style="color:red">温馨提示：发起培训确定后直接发起通知</span>
		</p>
	</div>
	<div style="width:100%;height:30px;">
		<div style="width:140px;float:right;margin-top:5px;">
			<a id="act-off" href="#" class="easyui-linkbutton" data-options="width:60,height:25">关闭</a>
			<a id="act-on" href="#" class="easyui-linkbutton" data-options="width:60,height:25">确定</a>
		</div>
	</div>
</div>
	</div>
	<script type="text/javascript">
	function add(text){
		$("#content-admin").panel({
			href:text
		});
	}
	//发起培训
		function peixun(b){
			$("#zhezhaoceng").show();
			$("#cours_id").val(b);
		}
	//发起申请
		function shenqing(ss,bb,cc){
			add("train-shenqing?apply_id="+ss+"&"+"pxapproval_id="+bb+"&"+"course_id="+cc);
		}
	//触发下拉列表
	function chose(a){
		$.ajax({
			url:"selectcoursebytype",
			type:"post",
			data:{"course_type":a},
			success:function(data){
	
			}
		});
	}
	$(function(){		
		//关闭弹窗
		$(".guanbiya").click(function(){
			$("#zhezhaoceng").hide();
		});
		//取消
		$("#act-off").click(function(){
			$("#zhezhaoceng").hide();
		});
		//确定
		$("#act-on").click(function(){
			var functionIds = [];
			var nodes = $('#qx_tree').tree('getChecked', ['checked','indeterminate']);
			//循环选中的节点
			for (var i = 0; i < nodes.length; i++) {
				//获取三级功能id，存入数组
				functionIds.push(nodes[i].id);
				/* //根据三级的节点，获取二级
				var parent = $("#qx_tree").tree("getParent",nodes[i].target);
				if(parent != null){
					functionIds.push(parent.id);
					//根据二级的节点，获取一级
					var root = $("#qx_tree").tree("getParent",parent.target);
					if(root != null){
						functionIds.push(root.id);
					}
				} */
			}
			
			//去重
			function dedupe(array){
				 return Array.from(new Set(array));
			}
			functionIds = dedupe(functionIds) //保证一级和二级在数组中不重复
			console.log(JSON.stringify(functionIds));
	    
			var a=$("#act-name").val();
			var b=JSON.stringify(functionIds);
			var c=$("#act-start").val();
			var d=$("#act-end").val();
			var e=$("#act-address").val();
			var f=$("#cours_id").val();
			var g=$("#staff_id").val();
			if(a==""||a==null){
				alert("请输入活动名称");
				return false;
			}else if(g==""||g==null){
				alert("请选择培训人员");
				return false;
			}else if(c==""||c==null){
				alert("请选择培训开始时间");
				return false;
			}else if(d==""||d==null){
				alert("请选择培训结束时间");
				return false;
			}else if(e==""||e==null){
				alert("请输入培训地点");
				return false;
			}else{
			    var c1=c.split("-");
				var d1=d.split("-");	
				if(c1[0]>d1[0] || c1[1]>d1[1] || c1[2]>d1[2] || c1[3]>d1[3] || c1[4]>d1[4]|| c1[5]>d1[5]){
					alert("开始时间不能大于结束时间,error!");
					return false;
				}else{
					$.ajax({
						url:"save-activity",
						type:"post",
						data:{"activityName":a,"staffids":b,"activityStartTime":c,"activityEndTime":d,"activityAddress":e,"course_id":f},
						success:function(data){
							$("#zhezhaoceng").hide();
							alert("发起培训成功");
							$("#content-admin").panel('open').panel('refresh','train-course');
						}
					});	
				}				
			}
		})
	})
	</script>
</body>
</html>